﻿using BLL;
using BLL.Access;
using DevExpress.Web;
using Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.Class;
using System.Data.OleDb;
using System.Text.RegularExpressions;

namespace Web.Pages.QuShui.DiXiaS._7.ChaXunGL
{
    public partial class QuanNianQSKXXCX : BasePage
    {
        #region 属性

        /// <summary>
        /// 保存结果集1
        /// </summary>
        private DataTable dtGrid1
        {
            get
            {
                return ViewState["dtGrid1"] as DataTable;
            }
            set
            {
                ViewState["dtGrid1"] = value;
            }
        }
        private DataTable dtGrid2
        {
            get
            {
                return ViewState["dtGrid2"] as DataTable;
            }
            set
            {
                ViewState["dtGrid2"] = value;
            }
        }
        private DataTable dtGrid2_2
        {
            get
            {
                return ViewState["dtGrid2_2"] as DataTable;
            }
            set
            {
                ViewState["dtGrid2_2"] = value;
            }
        }
        private DataTable dtGrid3
        {
            get
            {
                return ViewState["dtGrid3"] as DataTable;
            }
            set
            {
                ViewState["dtGrid3"] = value;
            }
        }

        private DataTable dtGrid4
        {
            get
            {
                return ViewState["dtGrid4"] as DataTable;
            }
            set
            {
                ViewState["dtGrid4"] = value;
            }
        }

        #endregion

        #region 变量

        /// <summary>
        /// 数据访问操作类
        /// </summary>
        SpHelper _SpHelper = new SpHelper();
        /// <summary>
        /// 行政区
        /// </summary>
        QS_JX_XINGZHENGQBLL XZQ = new QS_JX_XINGZHENGQBLL();
        /// <summary>
        /// 行业分类
        /// </summary>
        QS_JX_HANGYEFLXXBLL HYFL = new QS_JX_HANGYEFLXXBLL();
        /// <summary>
        /// 取水用途
        /// </summary>
        QS_JX_QUSHUIXXBLL QSYT = new QS_JX_QUSHUIXXBLL();
        /// <summary>
        /// 管理部门
        /// </summary>
        QS_JX_BUMENXXBLL GLBM = new QS_JX_BUMENXXBLL();
        /// <summary>
        /// 流域信息
        /// </summary>
        QS_JX_LIUYUXXBLL LYXX = new QS_JX_LIUYUXXBLL();
        /// <summary>
        /// 水利分片
        /// </summary>
        QS_JX_SHUILIFPXXBLL SLFP = new QS_JX_SHUILIFPXXBLL();
        /// <summary>
        /// 水资源分区
        /// </summary>
        QS_JX_SHUIZIYFQBLL SZYFQ = new QS_JX_SHUIZIYFQBLL();
        /// <summary>
        /// 井标记
        /// </summary>
        QS_JX_JINGBIAOJXXBLL JBJ = new QS_JX_JINGBIAOJXXBLL();
        #endregion

        #region 事件

        /// <summary>
        /// 页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            //第一次页面加载
            if (!IsPostBack)
            {
                InitData();
            }
            int index = ASPxPageControl1.ActiveTabIndex;
            switch (index)
            {
                case 0:
                    gvGrid1.DataSource = dtGrid1;
                    gvGrid1.DataBind();
                    break;
                case 1:
                    gvGridTab2.DataSource = dtGrid2;
                    gvGridTab2.DataBind();
                    break;
                case 2:
                    gvGridTab3.DataSource = dtGrid3;
                    gvGridTab3.DataBind();
                    break;
                case 3:
                    gvGridTab4.DataSource = dtGrid4;
                    gvGridTab4.DataBind();
                    break;
            };
            

        }




        /// <summary>
        /// 查询信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnChaXun_Click(object sender, EventArgs e)
        {
            try
            {
                int actindex = ASPxPageControl1.ActiveTabIndex;
                switch (actindex)
                {
                    case 0: LoadGrid1Data();
                        break;
                    case 1: LoadGrid2_3Data(1);
                        break;
                    case 2: LoadGrid2_3Data(2);
                        break;
                    case 3: LoadGrid4Data();
                        break;
                };
            }
            catch (Exception ex)
            {

            }

            if (this.dtGrid1 == null || this.dtGrid1.Rows.Count < 1)
            {
                txtYongHuH2.Text = "";
                txtYongHuM2.Text = "";
                txtHuanNeiHW.Text = "";
                txJingBianH.Text = "";
                txtDiZhi.Text = "";
                txtXingZhengQ.Text = "";
                txtJingLeiX.Text = "";
                txtQuShuiDD.Text = "";
                txtLiuYu.Text = "";
                txtQSFS.Text = "";
                txtShuiYuan.Text = "";
                txtTuiShuiWZ.Text = "";
                txtQSKPH.Text = "";
                txtQSKM.Text = "";
                txtQuShuiYT.Text = "";
                txtYeWuY.Text = "";
                txtGuanLiBM.Text = "";
                txtShuiZiYFQ.Text = "";
                txtHangYeFL.Text = "";
                txtShuiLiFP.Text = "";
                txtShuiBiaoSL.Text = "";
                //txtBenYueSL.Text = "";
                memoBeiZhu.Text = "";
                zjl.Text = "共0条";
            }
            if (this.dtGrid2 == null || this.dtGrid2.Rows.Count < 1)
            {
                gvGrid2Tab2.DataSource = null;
                gvGrid2Tab2.DataBind();
            }
        }




        #endregion

        #region 方法

        /// <summary>
        /// 初始化数据
        /// </summary>
        private void InitData()
        {
            int wtype = BusinessTool.WType;
            gvGrid1.SettingsPager.Mode = GridViewPagerMode.EndlessPaging;
            //水量年月
            string water_y_m = BusinessTool.GetSLYMorZWNY(1, wtype).ToString();


            //加载管理部门
            LoadGLBM();
            //加载行政区
            LoadXZQ();
            //加载业务员
            LoadYWY();
            //加载取水用途
            LoadQSYT();
            //加载行业分类
            LoadHYFL();
           
        }

        /// <summary>
        /// 加载业务员
        /// </summary>
        private void LoadYWY()
        {
            PageTools.QSLoadCombox(cmbYeWuY, PageTools.eLoadType.业务员QS, null, "");
        }

        /// <summary>
        /// 加载管理部门
        /// </summary>
        private void LoadGLBM()
        {
            DataTable dt = GLBM.SelectQS_JX_BUMENXXesDynamic("I_JLZT=0 and s_bumenbh not in('0','600')", null);
            cbmGuanLiBM.Items.Insert(0, new ListEditItem("", ""));
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                cbmGuanLiBM.Items.Add(dt.Rows[i]["S_BUMENMC"].ToString(), dt.Rows[i]["S_BUMENBH"]);
            }
            for (int i = DateTime.Now.Year - 10; i <= DateTime.Now.Year ; i++)
            {
                cmbYear.Items.Add(i.ToString(), i.ToString());
            }

            for (int i = 1; i <= 12; i++)
            {
                cmbMonth.Items.Add(i.ToString(), i.ToString());
            }
            cmbYear.Value = BusinessTool.GetSLYMorZWNY(1, BusinessTool.WType) / 100;
            cmbMonth.Value = BusinessTool.GetSLYMorZWNY(1, BusinessTool.WType) % 100;

            PageTools.QSLoadCombox(cmbLiuYu, PageTools.eLoadType.流域QS, null, "");
            

            QS_JX_SHUILIFPXXBLL fpbll = new QS_JX_SHUILIFPXXBLL();
            QS_JX_SHUIZIYFQBLL szybll = new QS_JX_SHUIZIYFQBLL();

            DataTable fpdt = fpbll.SelectQS_JX_SHUILIFPXXesDynamic("  i_jlzt=0 ", "");

            DataTable szydt = szybll.SelectQS_JX_SHUIZIYFQsAll();

            cmbShuiZiY.DataSource = szydt;
            cmbShuiZiY.TextField = "S_SHUIZIYMC";
            cmbShuiZiY.ValueField = "S_SHUIZIYBH";
            cmbShuiZiY.DataBind();
            cmbShuiZiY.Items.Insert(0, new ListEditItem("", ""));

            cmbShuiLiFP.DataSource = fpdt;
            cmbShuiLiFP.TextField = "S_SHUILIFPMC";
            cmbShuiLiFP.ValueField = "S_SHUILIFPBH";
            cmbShuiLiFP.DataBind();
            cmbShuiLiFP.Items.Insert(0, new ListEditItem("", ""));

        }

        /// <summary>
        /// 加载行政区
        /// </summary>
        private void LoadXZQ()
        {
            DataTable dt = XZQ.SelectQS_JX_XINGZHENGQsDynamic("I_JLZT=0", null);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                cmbXingZhengQ.Items.Add(dt.Rows[i]["S_XINGZHENGQM"].ToString(), dt.Rows[i]["S_XINGZHENGQH"]);
            }
        }


        /// <summary>
        /// 加载 取水用途
        /// </summary>
        private void LoadQSYT()
        {
            DataTable dt = QSYT.SelectQS_JX_QUSHUIXXesDynamic("I_JLZT=0", null);
            cmbQuShuiYT.Items.Insert(0, new ListEditItem("", ""));
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                cmbQuShuiYT.Items.Add(dt.Rows[i]["S_QUSHUIMC"].ToString(), dt.Rows[i]["S_QUSHUIBH"]);
            }
        }
        /// <summary>
        /// 加载行业分类
        /// </summary>
        private void LoadHYFL()
        {
            DataTable dt = HYFL.SelectQS_JX_HANGYEFLXXesDynamic("I_JLZT=0", null);
            cmbHangYeLX.Items.Insert(0, new ListEditItem("", ""));
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                cmbHangYeLX.Items.Add(dt.Rows[i]["S_FENLEIMC"].ToString(), dt.Rows[i]["S_FENLEIBH"]);
            }
        }



        

        private void LoadGrid1Data()
        {
            int ym = Convert.ToInt32(cmbYear.Value) * 100 + Convert.ToInt32(cmbMonth.Value);
            int y = Convert.ToInt32(cmbYear.Value);
            int m = Convert.ToInt32(cmbMonth.Value);
            int wtype = BusinessTool.WType;
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            if (txtYongHuH.Text.Trim().Length > 0)
            {
                sb.AppendFormat("  and  B.S_YONGHUH ='{0}' ", txtYongHuH.Text.Trim());
            }
            if (txtYongHuM.Text.Trim().Length > 0)
            {
                sb.AppendFormat("  and  B.S_YONGHUM  like '%{0}%' ", txtYongHuM.Text.Trim());
            }
            if (txtYongHuDZ.Text.Trim().Length > 0)
            {
                sb.AppendFormat("  and  B.S_DIZHI  like '%{0}%' ", txtYongHuDZ.Text.Trim());
            }
            if (txtJingBianH.Text.Trim().Length > 0)
            {
                sb.AppendFormat("  and  A.S_QUSHUIKBH like '%{0}%' ", txtJingBianH.Text.Trim());
            }
            if (txtXuKeZH.Text.Trim().Length > 0)
            {
                sb.AppendFormat("  and  A.S_XUKEZBH like '%{0}%' ", txtXuKeZH.Text.Trim());
            }
            if (txtQuShuiDZ.Text.Trim().Length > 0)
            {
                sb.AppendFormat("  and  A.S_QUSHUIDZ like '%{0}%' ", txtQuShuiDZ.Text.Trim());
            }
            if (cmbQuShuiYT.Value != null && cmbQuShuiYT.Value.ToString().Trim().Length > 0)
            {
                sb.AppendFormat("  and  B.S_QUSHUIYTBH = '{0}' ", cmbQuShuiYT.Value);
            }
            if (cmbHangYeLX.Value != null && cmbHangYeLX.Value.ToString().Trim().Length > 0)
            {
                sb.AppendFormat("  and  B.S_HANGYEBH = '{0}' ", cmbHangYeLX.Value);
            }
            if (cbmGuanLiBM.Value != null && cbmGuanLiBM.Value.ToString().Trim().Length > 0)
            {
                sb.AppendFormat("  and  B.S_BUMENBH = '{0}' ", cbmGuanLiBM.Value);
            }
            if (cmbLiuYu.Value != null && cmbLiuYu.Value.ToString().Trim().Length > 0 && Convert.ToInt32(cmbLiuYu.Value) > -1)
            {
                sb.AppendFormat("  and  B.S_LIUYUBH = '{0}' ", cmbLiuYu.Value);
            }
            if (cmbShuiZiY.Value != null && cmbShuiZiY.Value.ToString().Trim().Length > 0)
            {
                sb.AppendFormat("  and  B.S_SHUIZIYBH = '{0}' ", cmbShuiZiY.Value);
            }
            if (cmbShuiLiFP.Value != null && cmbShuiLiFP.Value.ToString().Trim().Length > 0)
            {
                sb.AppendFormat("  and  B.S_FENPIANBH = '{0}' ", cmbShuiZiY.Value);
            }

            if (cmbHuanNeiHW.Value != null && cmbHuanNeiHW.Value.ToString().Trim().Length > 0)
            {
                sb.AppendFormat("  and  B.S_HUANXIANBJ = '{0}' ", cmbHuanNeiHW.Value);
            }
            if (cmbXingZhengQ.Value != null && cmbXingZhengQ.Value.ToString().Trim().Length > 0)
            {
                sb.AppendFormat("  and  B.S_XINGZHENGQBH = '{0}' ", cmbXingZhengQ.Value);
            }

            if (cmbYeWuY.Value != null && cmbYeWuY.Value.ToString() != "-1")
            {
                sb.AppendFormat("  and  A.S_YEWUY = '{0}' ", cmbYeWuY.Value);
            }



            DataSet ds = _SpHelper.P_QS_CX_QUSHUIKXXCX(y, m, sb.ToString());

            dtGrid1 = ds.Tables[0];
            gvGrid1.DataSource = dtGrid1;
            gvGrid1.DataBind();
            zjl.Text = "共" + gvGrid1.VisibleRowCount + "条";
            gvGrid1.FocusedRowIndex = -1;
            gvGrid1.FocusedRowIndex = 0;
           
        }
        private void LoadGrid2_3Data(int type)
        {
            int ym = Convert.ToInt32(cmbYear.Value) * 100 + Convert.ToInt32(cmbMonth.Value);
            int y = Convert.ToInt32(cmbYear.Value);
            int m = Convert.ToInt32(cmbMonth.Value);
            int wtype = BusinessTool.WType;
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            if (txtYongHuH.Text.Trim().Length > 0)
            {
                sb.AppendFormat("  and  yh.S_YONGHUH ='{0}' ", txtYongHuH.Text.Trim());
            }
            if (txtYongHuM.Text.Trim().Length > 0)
            {
                sb.AppendFormat("  and  yh.S_YONGHUM  like '%{0}%' ", txtYongHuM.Text.Trim());
            }
            if (txtYongHuDZ.Text.Trim().Length > 0)
            {
                sb.AppendFormat("  and  yh.S_DIZHI  like '%{0}%' ", txtYongHuDZ.Text.Trim());
            }
            if (txtJingBianH.Text.Trim().Length > 0)
            {
                sb.AppendFormat("  and  qsk.S_QUSHUIKBH like '%{0}%' ", txtJingBianH.Text.Trim());
            }
            if (txtXuKeZH.Text.Trim().Length > 0)
            {
                sb.AppendFormat("  and  qsk.S_XUKEZBH like '%{0}%' ", txtXuKeZH.Text.Trim());
            }
            if (txtQuShuiDZ.Text.Trim().Length > 0)
            {
                sb.AppendFormat("  and  yh.S_QUSHUIDZ like '%{0}%' ", txtQuShuiDZ.Text.Trim());
            }
            if (cmbQuShuiYT.Value != null && cmbQuShuiYT.Value.ToString().Trim().Length > 0)
            {
                sb.AppendFormat("  and  yh.S_QUSHUIYTBH = '{0}' ", cmbQuShuiYT.Value);
            }
            if (cmbHangYeLX.Value != null && cmbHangYeLX.Value.ToString().Trim().Length > 0)
            {
                sb.AppendFormat("  and  yh.S_HANGYEBH = '{0}' ", cmbHangYeLX.Value);
            }
            if (cbmGuanLiBM.Value != null && cbmGuanLiBM.Value.ToString().Trim().Length > 0)
            {
                sb.AppendFormat("  and  yh.S_BUMENBH = '{0}' ", cbmGuanLiBM.Value);
            }
            if (cmbLiuYu.Value != null && cmbLiuYu.Value.ToString().Trim().Length > 0 && Convert.ToInt32(cmbLiuYu.Value) > -1)
            {
                sb.AppendFormat("  and  yh.S_LIUYUBH = '{0}' ", cmbLiuYu.Value);
            }
            if (cmbShuiZiY.Value != null && cmbShuiZiY.Value.ToString().Trim().Length > 0)
            {
                sb.AppendFormat("  and  yh.S_SHUIZIYBH = '{0}' ", cmbShuiZiY.Value);
            }
            if (cmbShuiLiFP.Value != null && cmbShuiLiFP.Value.ToString().Trim().Length > 0)
            {
                sb.AppendFormat("  and  yh.S_FENPIANBH = '{0}' ", cmbShuiZiY.Value);
            }
            double d = 0;

            if (cmbHuanNeiHW.Value != null && cmbHuanNeiHW.Value.ToString().Trim().Length > 0)
            {
                sb.AppendFormat("  and  yh.S_HUANXIANBJ = '{0}' ", cmbHuanNeiHW.Value);
            }
            if (cmbXingZhengQ.Value != null && cmbXingZhengQ.Value.ToString().Trim().Length > 0)
            {
                sb.AppendFormat("  and  yh.S_XINGZHENGQBH = '{0}' ", cmbXingZhengQ.Value);
            }

            if (cmbYeWuY.Value != null && cmbYeWuY.Value.ToString() != "-1")
            {
                sb.AppendFormat("  and  yh.S_YEWUY = '{0}' ", cmbYeWuY.Value);
            }

            DataSet ds = new DataSet();
            if (type == 1)
            {
                ds = _SpHelper.P_QS_CX_QUSHUIKQNYSCX(y, 0, sb.ToString());
                dtGrid2 = ds.Tables[0];
                gvGridTab2.DataSource = dtGrid2;
                gvGridTab2.DataBind();
                gvGridTab2.FocusedRowIndex = 0;
                zjltab2.Text = "共" + (gvGridTab2.VisibleRowCount-1) + "条";
            }
            else
            {
                ds = _SpHelper.P_QS_CX_QUSHUIKQNYSCX(y, m, sb.ToString());
                dtGrid3 = ds.Tables[0];
                gvGridTab3.DataSource = dtGrid3;
                gvGridTab3.DataBind();
                gvGridTab3.FocusedRowIndex = 0;
                zjltab3.Text = "共" + (gvGridTab3.VisibleRowCount-1) + "条";
            }

        }
        private void LoadGrid4Data()
        {
            int ym = Convert.ToInt32(cmbYear.Value) * 100 + Convert.ToInt32(cmbMonth.Value);
            int y = Convert.ToInt32(cmbYear.Value);
            int m = Convert.ToInt32(cmbMonth.Value);
            int wtype = BusinessTool.WType;
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            System.Text.StringBuilder sb1 = new System.Text.StringBuilder();
            if (txtYongHuH.Text.Trim().Length > 0)
            {
                sb.AppendFormat("  and  yh.S_YONGHUH ='{0}' ", txtYongHuH.Text.Trim());
            }
            if (txtYongHuM.Text.Trim().Length > 0)
            {
                sb.AppendFormat("  and  yh.S_YONGHUM  like '%{0}%' ", txtYongHuM.Text.Trim());
            }
            if (txtYongHuDZ.Text.Trim().Length > 0)
            {
                sb.AppendFormat("  and  yh.S_DIZHI  like '%{0}%' ", txtYongHuDZ.Text.Trim());
            }
            if (txtJingBianH.Text.Trim().Length > 0)
            {
                sb.AppendFormat("  and  A.S_JINGBH like '%{0}%' ", txtJingBianH.Text.Trim());
            }
            if (txtXuKeZH.Text.Trim().Length > 0)
            {
                sb.AppendFormat("  and  A.S_XUKEZHENGBH like '%{0}%' ", txtXuKeZH.Text.Trim());
            }
            if (txtQuShuiDZ.Text.Trim().Length > 0)
            {
                sb.AppendFormat("  and  yh.S_DIZHI like '%{0}%' ", txtQuShuiDZ.Text.Trim());
            }
            if (cmbQuShuiYT.Value != null && cmbQuShuiYT.Value.ToString().Trim().Length > 0)
            {
                sb.AppendFormat("  and  yh.S_QUSHUIYTBH = '{0}' ", cmbQuShuiYT.Value);
            }
            if (cmbHangYeLX.Value != null && cmbHangYeLX.Value.ToString().Trim().Length > 0)
            {
                sb.AppendFormat("  and  yh.S_HANGYEBH = '{0}' ", cmbHangYeLX.Value);
            }
            if (cbmGuanLiBM.Value != null && cbmGuanLiBM.Value.ToString().Trim().Length > 0)
            {
                sb.AppendFormat("  and  yh.S_BUMENBH = '{0}' ", cbmGuanLiBM.Value);
            }
            if (cmbLiuYu.Value != null && cmbLiuYu.Value.ToString().Trim().Length > 0 && Convert.ToInt32(cmbLiuYu.Value) > -1)
            {
                sb.AppendFormat("  and  yh.S_LIUYUBH = '{0}' ", cmbLiuYu.Value);
            }
            if (cmbShuiZiY.Value != null && cmbShuiZiY.Value.ToString().Trim().Length > 0)
            {
                sb.AppendFormat("  and  yh.S_SHUIZIYBH = '{0}' ", cmbShuiZiY.Value);
            }
            if (cmbShuiLiFP.Value != null && cmbShuiLiFP.Value.ToString().Trim().Length > 0)
            {
                sb.AppendFormat("  and  yh.S_FENPIANBH = '{0}' ", cmbShuiZiY.Value);
            }
            double d = 0;
           
            if (cmbHuanNeiHW.Value != null && cmbHuanNeiHW.Value.ToString().Trim().Length > 0)
            {
                sb.AppendFormat("  and  A.S_HUANXIANBJ = '{0}' ", cmbHuanNeiHW.Value);
            }
            if (cmbXingZhengQ.Value != null && cmbXingZhengQ.Value.ToString().Trim().Length > 0)
            {
                sb.AppendFormat("  and  YH.S_XINGZHENGQBH = '{0}' ", cmbXingZhengQ.Value);
            }

            if (cmbYeWuY.Value != null && cmbYeWuY.Value.ToString() != "-1")
            {
                sb.AppendFormat("  and  A.S_YEWUY = '{0}' ", cmbYeWuY.Value);
            }
            
            DataSet ds = _SpHelper.P_QS_CX_SHENSHUIYUEHZCX(1, y, m, sb.ToString(), cmbHuiZongLX.SelectedIndex, sb1.ToString());
            if (ds.Tables[0] != null)
            {
                var count = gvGridTab4.Columns.Count;
                while (gvGridTab4.Columns.Count > 0)
                {
                    gvGridTab4.Columns.RemoveAt(0);
                }
                foreach (DataColumn dc in ds.Tables[0].Columns)
                {

                    GridViewDataTextColumn c = new GridViewDataTextColumn();
                    c.FieldName = dc.ColumnName;
                    c.Caption = dc.ColumnName;

                    gvGridTab4.Columns.Add(c);
                }
            }
            dtGrid4 = ds.Tables[0];
            gvGridTab4.DataSource = dtGrid4;
            gvGridTab4.DataBind();
            gvGridTab4.FocusedRowIndex = 0;
            zjltab4.Text = "共" + (gvGridTab4.VisibleRowCount - 1) + "条";
        }
        

        /// <summary>
        /// 前台表格行改变事件回调方法
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            int id = Convert.ToInt32(this.hdCollection.Get("ID"));
            if (e.Parameter == "setinfo")
            {
                string msg = "";
                if (this.dtGrid1 != null)
                {
                    int y = Convert.ToInt32(cmbYear.Value);
                    int m = Convert.ToInt32(cmbMonth.Value);
                    string where = "";

                    where = " and A.ID='" + id + "'";

                    DataTable dt_temp = _SpHelper.P_QS_CX_QUSHUIKXXCX(y, m, where).Tables[0];

                    msg = string.Join("|",
                      dt_temp.Rows[0]["用户号"].ToString(),
                        dt_temp.Rows[0]["用户名"].ToString(),
                         dt_temp.Rows[0]["环内环外"].ToString(),
                        dt_temp.Rows[0]["取水口号"].ToString(),
                        dt_temp.Rows[0]["用户地址"].ToString(),
                         dt_temp.Rows[0]["行政区名"].ToString(),
                        dt_temp.Rows[0]["取水类型"].ToString(),
                         dt_temp.Rows[0]["取水地点"].ToString(),
                         dt_temp.Rows[0]["流域"].ToString(),
                         "",
                        //dt_temp.Rows[0]["取水方式"].ToString(),
                        dt_temp.Rows[0]["取水水源"].ToString(),
                        dt_temp.Rows[0]["退水位置"].ToString(),
                         dt_temp.Rows[0]["取水口牌号"].ToString(),
                        dt_temp.Rows[0]["取水口名"].ToString(),
                        dt_temp.Rows[0]["取水用途"].ToString(),
                        dt_temp.Rows[0]["业务员名"].ToString(),
                        dt_temp.Rows[0]["主管部门名称"].ToString(),
                        dt_temp.Rows[0]["水资源分区"].ToString(),
                        dt_temp.Rows[0]["行业分类"].ToString(),
                        dt_temp.Rows[0]["水利分片"].ToString(),
                         dt_temp.Rows[0]["表数"].ToString(),
                         "",
                        //dt_temp.Rows[0]["本月水量"].ToString(),
                        dt_temp.Rows[0]["备注"].ToString());
                }
               

                e.Result = e.Parameter + "|0|" + msg;
            }
        }
        #endregion



        protected void gvGrid2Tab2_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
        {
            string qsk = hdCollection.Contains("gvGrid2Tab2YHH") ? hdCollection.Get("gvGrid2Tab2YHH").ToString() : null;
            if (qsk != null && qsk != "合计")
            {
                int year = Convert.ToInt32(cmbYear.Value);
                int wtype = 1;
                DataSet ds = SearchSpHelper.P_QS_CX_QUANNIANQKCXXXXX(wtype, year, qsk);
                dtGrid2_2 = ds.Tables[0];
                gvGrid2Tab2.DataSource = dtGrid2_2;
                gvGrid2Tab2.DataBind();
            }
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            int index = ASPxPageControl1.ActiveTabIndex;
            string sName = "";
            if (index == 0)
            {
                ASPxGridViewExporter1.GridViewID = "gvGrid1";
                sName = "取水口信息";
                gvGrid1.DataSource = dtGrid1;
                gvGrid1.DataBind();
                gvGrid1.Settings.ShowFooter = false;
                for (int i = 0; i < this.dtGrid1.Rows.Count; i++)
                {
                    DataRow row = this.dtGrid1.Rows[i];
                    for (int j = 0; j < this.dtGrid1.Columns.Count; j++)
                    {
                        if (row[j].GetType().Equals(typeof(string)) && Regex.IsMatch(row[j].ToString(), @"^[+-]?\d*$"))
                        {
                            row[j] = "\r" + row[j];
                        }
                    }
                }
            }
            else if (index == 1)
            {
                ASPxGridViewExporter1.GridViewID = "gvGridTab2";
                sName = "取水口全年用水情况";
                gvGridTab2.DataSource = dtGrid2;
                gvGridTab2.DataBind();
                gvGridTab2.Settings.ShowFooter = false;
            }
            else if (index == 2)
            {
                ASPxGridViewExporter1.GridViewID = "gvGridTab3";
                sName = "取水口月用水情况";
                gvGridTab3.DataSource = dtGrid3;
                gvGridTab3.DataBind();
                gvGridTab3.Settings.ShowFooter = false;
            }
            else if (index == 3)
            {
                ASPxGridViewExporter1.GridViewID = "gvGridTab4";
                sName = "取水口月用水汇总";
                gvGridTab4.DataSource = dtGrid4;
                gvGridTab4.DataBind();
                gvGridTab4.Settings.ShowFooter = false;
            }

            ASPxGridViewExporter1.WriteXlsToResponse(sName);

        }



    }
}